package com.itheima.d5_resourse;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Test2 {
    public static void main(String[] args) {
        InputStream is = null;
        FileOutputStream os= null;
        try {
            //需求复制照片
            //创建字节输入流管道与源文件接通
             is = new FileInputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima04out.txt");
            //创建字节输出流管道和目标文件接通
            os = new FileOutputStream("D:\\Java\\JavaEE_learn\\IO_learn\\src\\main\\java\\com\\itheima\\itheima04outCopy.tx");

            //接收所有的字节输入流
//        byte[] bytes = is.readAllBytes();
            byte[] bytes = new byte[1024];
            int len;
            if((len =is.read(bytes)) != -1){
                os.write(bytes,0,len);
            }

            System.out.println("复制完成·");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            //判断os,is不能为空
//        os.write(bytes);
            try {
                if(os !=null) os.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                if(is != null) is.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
